package com.example.lxc415billiards.controller;

import com.example.lxc415billiards.domain.BilliardCue;
import com.example.lxc415billiards.service.BilliardCueService;
import com.example.lxc415billiards.untils.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/billiardCue")
@Api(tags = "台球杆管理-李效丞0415")
public class BilliardCueController {

    @Autowired
    private BilliardCueService billiardCueService;

    @ApiOperation("获取所有台球杆信息")
    @GetMapping("/getAllCues")
    public AjaxResult getAllCues() {
        List<BilliardCue> cues = billiardCueService.getAllCues();
        return AjaxResult.success(cues);
    }

    @ApiOperation("根据ID获取台球杆信息")
    @GetMapping("/getCueById/{id}")
    public AjaxResult getCueById(@PathVariable int id) {
        BilliardCue cue = billiardCueService.getCueById(id);
        return cue != null ? AjaxResult.success(cue) : AjaxResult.error("台球杆不存在");
    }

    @ApiOperation("新增台球杆")
    @PostMapping("/addCue")
    public AjaxResult addCue(@RequestBody BilliardCue cue) {
        BilliardCue newCue = billiardCueService.addCue(cue);
        return AjaxResult.success(newCue);
    }

    @ApiOperation("根据ID删除台球杆")
    @DeleteMapping("/deleteCueById/{id}")
    public AjaxResult deleteCueById(@PathVariable int id) {
        billiardCueService.deleteCueById(id);
        return AjaxResult.success("删除成功");
    }

    @ApiOperation("修改台球杆信息")
    @PutMapping("/updateCue")
    public AjaxResult updateCue(@RequestBody BilliardCue cue) {
        BilliardCue updatedCue = billiardCueService.updateCue(cue);
        return updatedCue != null ? AjaxResult.success(updatedCue) : AjaxResult.error("更新失败");
    }
}
